package com.sk.skplanet.commute.controllers;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.sk.skplanet.commute.R;
import com.sk.skplanet.commute.actions.Actions;
import com.sk.skplanet.commute.vo.Data;
import com.sk.skplanet.commute.vo.Point;
import com.sk.skplanet.commute.vo.Route;
import com.sk.skplanet.commute.vo.StopInfo;

public class PointController {

	/**
	 * 북마크 항목 내 내부 위치, 버스정보를 담은 레이아웃 생성 메소드
	 * 
	 * @param : 북마크 액티비티의 컨텍스트
	 * @return : 내부 위치, 버스정보를 담은 레이아웃
	 */
	public static LinearLayout makePoint(final Context context, final int routePostion, final int pointPosition) {
		final Route route = Data.memberData.getRoutes().get(routePostion);
		final Point point = (Point) route.getPoints().get(pointPosition);

		// 포인트 레이아웃 설정 부분
		LinearLayout layout_point = new LinearLayout(context);
		layout_point.setOrientation(LinearLayout.VERTICAL);
		LayoutParams layoutParams_layout_point = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT);
		layoutParams_layout_point.setMargins(0, Actions.DPFromPixel(5), 0, Actions.DPFromPixel(5));
		layout_point.setPadding(Actions.DPFromPixel(10), Actions.DPFromPixel(10), Actions.DPFromPixel(10),
				Actions.DPFromPixel(10));
		layout_point.setLayoutParams(layoutParams_layout_point);
		layout_point.setBackgroundColor(Color.parseColor(Data.layout_pointColor));
		
		layout_point.setOnLongClickListener(new OnLongClickListener() {
			
			@Override
			public boolean onLongClick(View v) {
				DialogController.createDeleteDialog(context, point, v).show();
				return true;
			}
		});
		
		{
			LinearLayout layout_pointTitle = new LinearLayout(context);
			layout_pointTitle.setOrientation(LinearLayout.HORIZONTAL);
			{// 포인트 텍스트뷰 설정 부분
				TextView textview_point = new TextView(context);
				textview_point.setText(point.getName());
				textview_point.setTextColor(Color.parseColor(Data.textview_routeColor));
				textview_point.setTextSize((float) Actions.DPFromPixel(15));

				android.view.ViewGroup.LayoutParams layoutParams_textview_route = new LayoutParams(
						LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1);
				textview_point.setLayoutParams(layoutParams_textview_route);
				layout_pointTitle.addView(textview_point);
			}
			{// 스탑인포 추가 버튼 설정 부분
				Button button_point_addstopinfo = new Button(context);
				android.view.ViewGroup.LayoutParams layoutParams_button_point_addstopinfo = new LayoutParams(
						Actions.DPFromPixel(40), Actions.DPFromPixel(40), 0);
				button_point_addstopinfo.setBackgroundResource(R.drawable.ic_add_layout);
				button_point_addstopinfo.setLayoutParams(layoutParams_button_point_addstopinfo);
				button_point_addstopinfo.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						DialogController.createStationDialog(context, routePostion, pointPosition).show();
					}
				});
				layout_pointTitle.addView(button_point_addstopinfo);
			}
			layout_point.addView(layout_pointTitle);
		}

		{// 인포 레이아웃 설정 부분

			List<StopInfo> list = point.getStopInfos();

			if (list != null) {
				for (StopInfo info : list) {
					layout_point.addView(StopInfoController.makeInfo(context, info));
				}
			}

		}

		return layout_point;
	}
}
